<!-- 地点管理 - 综合表单页面 -->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">
    </ex_super_table_page>

    <placeImport ref="importRef" @submitSuccess="$refs['SuperTablePage'].reload()" />
  </div>
</template>
<script>
import placeImport from './dialog/place_import.vue';
import superTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'tms>place_manage'
export default {
  title: "title_place_manage",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components:{placeImport},
  data() {
    return {
      selection: [],
      option: {
        search: {
          model: [
            { label: "label_place_query", key: "strFullIndex", },
            { key: 'placeTypes', label: 'label_place_type', type: 'select', enum: 'PlaceTypeEnum',multiple:true,listHandler:list=>list.filter(item=>item!=='SERVICE_OUTLET') },
            { key: 'status', label: 'label_status', type: 'select', enum: 'IsAvailableStatusEnum' },
            { key: 'placeBelong', label: 'label_place_belong', type: 'select', enum: 'PlaceBelongEnum' },
          ],
        },
        actionExtra: [
        {
            label: 'title_create_place', attrs: { icon: "el-icon-plus" },
            auth: 'tms_place_manage_edit',
            attrs: { type: "primary" },
            click: this.clickCreate
          },
          {
            label: 'label_export',
            auth: 'tms_place_manage_export',
            click: this.exportExcel
          },
          {
            label: 'label_import',
            click: this.importFn
          },
        ],
        table: {
          url: "/tms-api/base/TmsPlaceInfoRpc/selectByPage.json",
          model: this.init_table_model(),
        }
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, },


        { key: 'placeName', label: 'label_place_name', 'min-width': 140, 'show-overflow-tooltip': true, },
        { key: 'placeAbb', label: 'label_place_abb', 'min-width': 120, 'show-overflow-tooltip': true, },
        { key: 'placeBelong', label: 'label_place_belong', 'min-width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "PlaceBelongEnum")
        },
        {
          key: 'placeType', label: 'label_place_type', 'min-width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "PlaceTypeEnum")
        },
        {
          key: 'status', label: 'label_status', 'min-width': 120, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "IsAvailableStatusEnum")
        },
        { key: 'address', label: 'label_detail_address', 'min-width': 120, 'show-overflow-tooltip': true, },
        { key: 'postalCode', label: 'label_post_code', 'width': 120, 'show-overflow-tooltip': true, },
        {
          type: 'operate', width: 160, operate: [
            {
              label: 'label_edit',
              auth: 'tms_place_manage_edit',
              click: (row) => this.clickEdit(row)
            },
            {
              if: (row) => row.status == 'ENABLE',
              auth: 'tms_place_manage_disable',
              label: 'label_stop_using', type: "confirm-button", buttonClass: "button_text_danger", confirmButtonType: 'danger',
              url: '/tms-api/base/TmsPlaceInfoRpc/enableOrDisable.json', message: 'text_confirm_sure_stop_using_operate',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },
            {
              if: (row) => row.status == 'DISABLED',
              auth: 'tms_place_manage_disable',
              label: 'label_start_using', type: "confirm-button", buttonClass: "button_text_success", confirmButtonType: 'success',
              url: '/tms-api/base/TmsPlaceInfoRpc/enableOrDisable.json', message: 'text_confirm_sure_start_using_operate',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },
            {
              label: 'label_delete',
              auth: 'tms_place_manage_delete',
              type: "confirm-button", buttonClass: "button_text_danger", confirmButtonType: 'danger',
              url: '/tms-api/base/TmsPlaceInfoRpc/remove.json', message: 'text_confirm_sure_delete',
              params: (row) => { return { "id": row["id"] } }, done: ['reload', 'tip']
            },
          ],
        }
      ]
    },
    clickCreate() {
      this.$router.push({ path: '/page/tms/base/place_operate', query: { emitKey } })
    },
    clickEdit(row) {
      this.$router.push({ path: '/page/tms/base/place_operate', query: { id: row.id, edit: true, emitKey } })
    },
    exportExcel() {
      this.$downloadFile({
        loading: true,
        type: 'json',
        url: '/tms-api/base/TmsPlaceInfoRpc/exportExcel.json',
        data: {
          placeIds: this.selection.map(it => it.id),
          ...this.getSuperTablePage().getSearchFormData()
        },
      })
    },
    importFn() {
      this.$refs.importRef.show()
    }
  }
};

</script>
<style></style>

